<template>
  <div>
    <el-container>
      <el-header>
        <i class="el-icon-arrow-left"></i>
        Header
      </el-header>
      <el-main>
        <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="80px" class="demo-ruleForm"
                 label-position="left">

          <el-form-item prop="myAccount" label="转出账户">
            <el-select v-model="ruleForm2.myAccount" placeholder="请选择" style="width: 100%" >
              <el-option
                :label="item.name"
                :value="item.id"
                v-for="item of myAccount"
              >
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="收款户名" prop="toName">
            <el-input type="text" v-model="ruleForm2.toName" auto-complete="off"></el-input>
          </el-form-item>

          <el-form-item label="收款账号" prop="toCount">
            <el-input type="text" v-model="ruleForm2.toCount" auto-complete="off"></el-input>
          </el-form-item>

          <el-form-item label="收款银行" prop="toBank">
            <el-input v-model="ruleForm2.toBank"></el-input>
          </el-form-item>

          <el-form-item label="汇款金额" prop="toMoney">
            <el-input type="number" v-model="ruleForm2.toMoney"></el-input>
          </el-form-item>

          <el-form-item label="收款附言">
            <el-input v-model="ruleForm2.comment"></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm2')">提交</el-button>
            <el-button @click="resetForm('ruleForm2')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-main>
    </el-container>
  </div>
</template>

<script>
  import { mapState, mapMutations } from 'vuex'
  export default {
    data() {
      var checkmyAccount = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请选择账户！'));
        } else {
          callback();
        }
      };
      var checktoName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入户名！'));
        } else {
          callback();
        }
      };
      var checktoCount = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入卡号！'));
        } else {
          callback();
        }
      };
      var checktoBank = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入银行！'));
        } else {
          callback();
        }
      };
      var checktoMoney = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入金额！'));
        } else {
          callback();
        }
      };

      return {
        ruleForm2: {
          myAccount: '',
          toName: '',
          toCount: '',
          toBank: '',
          toMoney: '',
          comment: ''
        },
        rules2: {
          myAccount: [
            {validator: checkmyAccount, trigger: 'blur'}
          ],
          toName: [
            {validator: checktoName, trigger: 'blur'}
          ],
          toCount: [
            {validator: checktoCount, trigger: 'blur'}
          ],
          toBank: [
            {validator: checktoBank, trigger: 'blur'}
          ],
          toMoney: [
            {validator: checktoMoney, trigger: 'blur'}
          ]
        }
      };
    },
    computed:{
      ...mapState(['myAccount'])
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.changemyselectAccountId(this.ruleForm2.myAccount);
            this.changecomment(this.ruleForm2.comment);
            this.changetoName(this.ruleForm2.toName);
            this.changetoCount(this.ruleForm2.toCount);
            this.changetoBank(this.ruleForm2.toBank);
            this.changetoMoney(this.ruleForm2.toMoney);
            this.$router.push('/TransferConfirm')
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      ...mapMutations(['changemyselectAccountId','changetoName','changetoCount','changetoBank','changetoMoney','changecomment'])
    }
  }
</script>

<style scoped>
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
  }

  .el-icon-arrow-left {
    color: #fff;
    position: relative;
    top: 0px;
    left: -130px;
    font-size: 20px;
  }
</style>
